<?php
/*
 *      View.php
 *
 *      Copyright 2010 Rakitin Vitaliy <virak@ukr.net>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

//require_once("./config.php");
//require_once("DB.php");
//require_once("./classes/GUI/nwfform.php");
require_once("./classes/System/osmetadata.php");

class View {

	//function __construct($uuid) {
		//parent::__construct($uuid);

	//}

	static function displayLogout() {
		$out = "<div align=right>";
		//$out .= "Вы вошли как: ". $_SESSION['user_id'] . " ";
		//$out .= "Вы вошли как: ". $_SESSION['model']->users->currentUser->login . " ";
		$out .= "Вы вошли как: Безлогинный";
		//$out .= "<input type='submit' name='submit' value='Выйти'>";
		//$out .= "<input type='hidden' name='owner' value='logout'>";
		$out .= "</div>";
		return $out;
	}

	static function displayDefault() {
		$out = View::displayLogout();
		$out .= "<HR>";
		$out .= View::displayMenu();
		$out .= "<HR>";
		$out .= "<table style=width:100%><tr><td id='navigator' valign=top style=width:10%>";
		$out .= View::displayNavigator();
		$out .= "</td><td id='viewer' valign=top>";
		$out .= View::displayViewer();
		$out .= "</td><td valign=top style=width:10%>";
		$out .= View::displayProperties();
		$out .= "</td></tr></table>";
		return $out;
	}

	static function displayViewer() {
		$out = "<fieldset id='b0bbc2f9e3254f5e970fb010294fd61b'><legend>Просмотр</legend>";
		//$out .= "<b>Окно просмотра</b><br>предназначено для просмотра и изменения данных";
		$out .= View::get_curr_form();
		$out .="</fieldset>";
		return $out;
	}

	static function displayNavigator($uuid = NULL, $self = NULL) {
		$out = "<fieldset id='0b1b455ed72c44bb9e9b07a9ad6b26ca'><legend>Навигатор</legend>";
		//$out .= "<b>Окно навигатор</b><br>предназначено для навигации";
		$out .= View::get_navi();
		$out .= "</fieldset>";
		return $out;
	}

	static function displayProperties() {
		$out = "<fieldset><legend>Свойтва</legend>";
		$out .= "</fieldset>";
		return $out;
	}

	static function displayAuth() {
		$out = "<form method='POST' action=''>";
		$out .= "<table><tr><td>Логин:</td><td><input type='text' name='login' /></td></tr>";
        $out .= "<tr><td>Пароль:</td><td><input type='password' name='pass' /></td></tr>";
        $out .= "<tr><td><input type='hidden' name='owner' value='auth'></td><td><input type='submit' name='submit' value='Войти' /></td></tr></table>";
		$out .= "</form>";
		return $out;
	}
	
	static function get_curr_form() {
		//return $osmetadata->objects->count();
		if (isset($_SESSION['object'])) {
			return $GLOBALS["metadata"]->objects->byuuid($_SESSION['object'])->defaultlistform->get();
			//return $_SESSION['object'];
		}
	}
	
	static function get_navi() {
		$objects = $GLOBALS["metadata"]->objects->getall();
		//echo "<pre>";
		//print_r($objects);
		//echo "</pre>";
		$out = "";
		foreach($objects as $object) {
			$out .= "<form method='POST' action=''>";
			$out .= "<input type='hidden' name='owner' value='navigator'>";
			$out .= "<input type='hidden' name='object' value='".$object["id"]."'>";
			$out .= "<input type='submit' name='submit' value='".$object["description"]."'>";
			$out .= "</form>";
			//$out .= "sfsfds";
		}
		return $out;
	}

	static function displayMenu() {

			//return $out;
	}

} // class View
?>
